package system.track;

/**
 * This provides special behavior for block 8.
 *
 * This is because in the counter clockwise direction there is
 * no switch, so get next block needs to be overridden to
 * provide block 9 directly  Also, the getters and setters
 * for the switches need to handle this special case.
 *
 * @author David Kolb
 */
public class Block8 extends Block
{
    private Block ccwBlock;

    public Block8()
    {
        super(8);
    }

    public void setCCWBlock(Block ccwBlock)
    {
        this.ccwBlock = ccwBlock;
    }

    @Override
    public Switch getSwitch(Direction d)
    {
        Switch returnVal = null;
        if (d != Direction.COUNTERCLOCKWISE)
        {
            returnVal = super.getSwitch(d);
        }
        return returnVal;
    }

    @Override
    public void setSwitch(Direction d, Switch s)
    {
        if (d != Direction.COUNTERCLOCKWISE)
        {
            super.setSwitch(d, s);
        }
    }

    @Override
    public Block getNextBlock(Direction d)
    {
        Block returnVal = this.ccwBlock;
        if (d != Direction.COUNTERCLOCKWISE)
        {
            returnVal = super.getNextBlock(d);
        }
        return returnVal;
    }

    @Override
    public Block getSpecificBlock(Direction d, SwitchAngle a)
    {
        Block returnVal = this.ccwBlock;
        if (d != Direction.COUNTERCLOCKWISE)
        {
            returnVal = super.getSpecificBlock(d, a);
        }
        return returnVal;
    }

    @Override
    public synchronized void autoSetSwitch(Direction d)
    {
        if (d != Direction.COUNTERCLOCKWISE)
        {
            super.autoSetSwitch(d);
        }
    }
}
